package org.zsk.fastdev.common;

public class StringOpt {
    /**
     * 获取属性getter方法名称
     * @param field 属性
     * @return getter方法名称
     */
    public static String getGetter(String field) {
        StringBuilder fieldStringBuilder=new StringBuilder("get");
        fieldStringBuilder.append(Character.toUpperCase(field.charAt(0)));
        fieldStringBuilder.append(field.substring(1));
        return fieldStringBuilder.toString();
    }
    /**
     * 获取属性setter方法名称
     * @param field 属性
     * @return setter方法名称
     */
    public static String getSetter(String field) {
        StringBuilder fieldStringBuilder=new StringBuilder("set");
        fieldStringBuilder.append(Character.toUpperCase(field.charAt(0)));
        fieldStringBuilder.append(field.substring(1));
        return fieldStringBuilder.toString();
    }
    /**
     * 获取字段名称
     * @param field 属性
     * @return 该属性字段名称
     */
    public static String getColumnName(String field) {
        StringBuilder columnNameBuilder=new StringBuilder();
        char[] columnNameChars=field.toCharArray();
        for (char columnNameChar : columnNameChars) {
            if (Character.isLowerCase(columnNameChar)) {
                columnNameBuilder.append(columnNameChar);
            } else {
                columnNameBuilder.append("_").append(Character.toLowerCase(columnNameChar));
            }
        }
        return columnNameBuilder.toString();
    }
    /**
     * 简单类名转换为参数名（如：User ==> user)
     * @param entity
     * @return
     */
    public static String getClazzName2fieldName(String entity) {
        return Character.toLowerCase(entity.charAt(0))+entity.substring(1);
    }
}
